package com.kichina.galaxy.dev.tools.init;


import com.alibaba.excel.EasyExcel;
import com.kichina.galaxy.dev.tools.excel.easyexcel.DemoDataListener;
import com.kichina.galaxy.dev.tools.excel.easyexcel.model.ExcelModel;
import com.kichina.galaxy.dev.tools.logic.service.IotDevicePointProtocolService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author Surging
 * @version 1.0
 * @ClassName DataDealInit
 * @date 2022/5/27 0:42
 * @desc
 */
@Component
@Slf4j
public class DataDealInit implements IInit {

    private final IotDevicePointProtocolService iotDevicePointProtocolService;

    public DataDealInit(IotDevicePointProtocolService iotDevicePointProtocolService) {
        this.iotDevicePointProtocolService = iotDevicePointProtocolService;
    }

    @Override
    public void init() throws InterruptedException {
        //String path = "F:\\workproject\\fxd\\dev-tools\\a测试文档\\设备协议文档\\";
        String path = "D:\\project\\company1.0\\template-tools\\aliyun-tools\\a测试文档\\设备协议文档\\";
        //D:\project\company1.0\template-tools\aliyun-tools\a测试文档\设备协议文档\智能土壤传感器-3185.xlsx
        //由于阿里物模型添加有长度限制，所以大量的物模型数据必须分批导入
        String fileName = path + "二键智能无线遥控器.xlsx";
        //String path = "F:\\workproject\\fxd\\dev-tools\\a测试文档\\poi\\";
        //String fileName = path + "物模型推送测试.xlsx";
        // 这里 需要指定读用哪个class去读，然后读取第一个sheet 文件流会自动关闭
        EasyExcel.read(fileName, ExcelModel.class, new DemoDataListener(iotDevicePointProtocolService)).sheet().doRead();

        // 读取全部sheet
        // 这里需要注意 DemoDataListener的doAfterAllAnalysed 会在每个sheet读取完毕后调用一次。然后所有sheet都会往同一个DemoDataListener里面写
        //EasyExcel.read(fileName, ExcelModel.class, new DemoDataListener(iotDevicePointProtocolService)).doReadAll();

    }
}
